package com.woniuxy.publisher;

import com.woniuxy.util.ConstantUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class CodePublisher implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnCallback{
    @Resource
    private RabbitTemplate rabbitTemplate;
    @Resource
    private RedisTemplate redisTemplateInit;

    public void sendCode(String msg){
        rabbitTemplate.convertAndSend(ConstantUtil.REGISTER_EXCHANGE,
                ConstantUtil.REGISTER_ROUTING_KEY,
                msg);
    }

    @Override
    public void confirm(CorrelationData correlationData, boolean flag, String s) {
        if (!flag){
            log.error("消息发送失败：{}",s);
        }
    }

    @Override
    public void returnedMessage(Message message, int i, String s, String s1, String s2) {
    }
}
